Completed
Push — master ( fa76b5...b46f0e )
by Mathieu
21s queued 11s
created

LeaveRequest.getId   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
1
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
2
import { User } from '../User/User.entity';
3
4
export enum Status {
5
  PENDING = 'pending',
6
  ACCEPTED = 'accepted',
7
  REFUSED = 'refused'
8
}
9
10
export enum Type {
11
  PAID = 'paid',
12
  UNPAID = 'unpaid',
13
  SPECIAL = 'special',
14
  MEDICAL = 'medical'
15
}
16
17
@Entity()
18
export class LeaveRequest {
19
  @PrimaryGeneratedColumn('uuid')
20
  private id: string;
21
22
  @Column('enum', {enum: Status, nullable: false})
23
  private status: Status;
24
25
  @Column('enum', {enum: Type, nullable: false})
26
  private type: Type;
27
28
  @Column({type: 'timestamp', nullable: false})
29
  private startDate: string;
30
31
  @Column({type: 'boolean', nullable: false, default: true})
32
  private startsAllDay: boolean;
33
34
  @Column({type: 'timestamp', nullable: false})
35
  private endDate: string;
36
37
  @Column({type: 'boolean', nullable: false, default: true})
38
  private endsAllDay: boolean;
39
40
  @Column({type: 'varchar', nullable: true})
41
  private comment: string;
42
43
  @Column({type: 'varchar', nullable: true})
44
  private moderationComment: string;
45
46
  @Column({type: 'timestamp', nullable: true})
47
  private moderateAt: string;
48
49
  @ManyToOne(type => User, {nullable: true})
50
  private moderator: User;
51
52
  @ManyToOne(type => User, {nullable: false})
53
  private user: User;
54
55
  constructor(
56
    user: User,
57
    type: Type,
58
    startDate: string,
59
    startsAllDay: boolean,
60
    endDate: string,
61
    endsAllDay: boolean,
62
    comment?: string
63
  ) {
64
    this.status = Status.PENDING;
65
    this.user = user;
66
    this.type = type;
67
    this.startDate = startDate;
68
    this.startsAllDay = startsAllDay;
69
    this.endDate = endDate;
70
    this.endsAllDay = endsAllDay;
71
    this.comment = comment;
72
  }
73
74
  public getId(): string {
75
    return this.id;
76
  }
77
78
  public getUser(): User {
79
    return this.user;
80
  }
81
82
  public getStatus(): Status {
83
    return this.status;
84
  }
85
86
  public getType(): Type {
87
    return this.type;
88
  }
89
90
  public getStartDate(): string {
91
    return this.startDate;
92
  }
93
94
  public isStartsAllDay(): boolean {
95
    return this.startsAllDay;
96
  }
97
98
  public getEndDate(): string {
99
    return this.endDate;
100
  }
101
102
  public isEndsAllDay(): boolean {
103
    return this.endsAllDay;
104
  }
105
106
  public getComment(): string {
107
    return this.comment;
108
  }
109
110
  public getModerator(): User {
111
    return this.moderator;
112
  }
113
114
  public getModerateAt(): string {
115
    return this.moderateAt;
116
  }
117
118
  public getModerationComment(): string {
119
    return this.moderationComment;
120
  }
121
122
  public refuse(
123
    moderator: User,
124
    date: string,
125
    moderationComment?: string
126
  ): void {
127
    this.status = Status.REFUSED;
128
    this.moderator = moderator;
129
    this.moderateAt = date;
130
    this.moderationComment = moderationComment;
131
  }
132
133
  public accept(
134
    moderator: User,
135
    date: string,
136
    moderationComment?: string
137
  ): void {
138
    this.status = Status.ACCEPTED;
139
    this.moderator = moderator;
140
    this.moderateAt = date;
141
    this.moderationComment = moderationComment;
142
  }
143
}
144